package com.baidu.roomdemo.fragment

import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.baidu.roomdemo.R
import com.baidu.roomdemo.databinding.FragmentHomeBinding
import com.baidu.roomdemo.db.User
import com.baidu.roomdemo.viewmodel.MainViewModel

class HomeFragment:BaseFragment<FragmentHomeBinding>() {
    private val mViewModel:MainViewModel by activityViewModels()

    override fun initBinding(): FragmentHomeBinding {
        return FragmentHomeBinding.inflate(layoutInflater)
    }

    override fun initView() {
        mBinding.button.setOnClickListener {
            val user = User(
                0,
                mBinding.etName.text.toString(),
                mBinding.evLastName.text.toString(),
                mBinding.evAge.text.toString().toInt()
            )
            mViewModel.saveUser(user)

            //切换到下一个界面
            findNavController().navigate(R.id.action_homeFragment_to_listFragment)
        }
    }
}